package com.panshi.modules.controller;

import com.panshi.api.CarouselApi;
import com.panshi.modules.service.CarouselService;
import com.panshi.vo.CarouselVO;
import com.panshi.vo.CodeMsgConstant;
import com.panshi.vo.R;
import com.panshi.vo.StatusVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/sys/carousel")
public class CarouselController implements CarouselApi {

    @Autowired
    private CarouselService carouselService;

    @Override
    @PostMapping("/list")
    public R listCarousel(@RequestBody(required = false) StatusVO statusVO) {
        List<CarouselVO> list = carouselService.listCarousel(statusVO);
        System.out.println(list);
        if(list.size() > 0){
            return R.ok(CodeMsgConstant.CODE_0).data("data",list).data("code",0);
        }
        return R.error(CodeMsgConstant.CODE_1);
    }

    @Override
    @PutMapping("/edit")
    public R editCarousel(@RequestBody CarouselVO carouselVO) {
        int edit = carouselService.editCarousel(carouselVO);
        if(edit > 0){
            return R.ok(CodeMsgConstant.CODE_0);
        }
        return R.error(CodeMsgConstant.CODE_1);
    }

    @Override
    @PostMapping("/add")
    public R addCarousel(@RequestBody CarouselVO carouselVO) {
        int add = carouselService.addCarousel(carouselVO);
        if(add > 0){
            return R.ok(CodeMsgConstant.CODE_0);
        }
        return R.error(CodeMsgConstant.CODE_1);
    }


}
